package com.suisung.shopsuite.pay;

import cn.hutool.crypto.SecureUtil;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class NihaopaySecurePay1 {

    public static void main(String[] args) throws Exception {
        String id = "20240716023723109189";
        int  amount = 107;
        String currency = "HKD";
        int rmb_amount = 100;
        String reference = "HO-20240716-1";
        String sys_reserve = "{'vendor_id':'2024071622001359521447751397'}";
        String status = "success";
        String time = "2024-07-16T02:41:11Z";
        String note = null;
        String verify_sign = "1365c60404136bc84a58607ea3111319";
        String c = SecureUtil.md5("816151c8f7520ccff745c169e2c95fd8dce8c29dbe338d079d9090174641e1f0");

        String a = "id="+id+"&amount="+amount+"&currency="+currency+"&rmb_amount="+rmb_amount+"&time="+time+"&reference="+reference+"&sys_reserve="+sys_reserve+"&status="+status;
        List<String> pairs = Arrays.asList(a.split("&"));

        // 对键值对按照key进行升序排序
        Collections.sort(pairs);

        // 重新构建排序后的字符串
        String sortedString = pairs.stream().collect(Collectors.joining("&"));
        System.out.println(sortedString);

        String d = sortedString+"&"+c;

        String b = SecureUtil.md5(d);
        System.out.println(b);
    }
}



